package test;


import com.alibaba.fastjson.JSONObject;
import com.tenqian.CONSTANT;
import com.tenqian.utils.HttpClientUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/*
 * Gson: https://github.com/google/gson
 * Maven info:
 *     groupId: com.google.code.gson
 *     artifactId: gson
 *     version: 2.8.1
 *
 * Once you have compiled or downloaded gson-2.8.1.jar, assuming you have placed it in the
 * same folder as this file (BingWebSearch.java), you can compile and run this program at
 * the command line as follows.
 *
 * javac BingWebSearch.java -classpath .;gson-2.8.1.jar -encoding UTF-8
 * java -cp .;gson-2.8.1.jar BingWebSearch
 */

public class BingWebSearch {

// ***********************************************
// *** Update or verify the following values. ***
// **********************************************

    // Replace the subscriptionKey string value with your valid subscription key.
    static String subscriptionKey = "6ed72a44ec054b66a06cc81bd522adbb";

    // Verify the endpoint URI.  At this writing, only one endpoint is used for Bing
    // search APIs.  In the future, regional endpoints may be available.  If you
    // encounter unexpected authorization errors, double-check this value against
    // the endpoint for your Bing Web search instance in your Azure dashboard.
    static String host = "https://api.cognitive.microsoft.com";
    static String path = "/bing/v7.0/videos/search";

    static String searchTerm = "精武门";

    public static String SearchWeb(String searchQuery) throws Exception {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("Accept-Language", "zh-CN");
        headerMap.put("Ocp-Apim-Subscription-Key", subscriptionKey);
        JSONObject jsonObject = HttpClientUtils.httpGet(host + path + "?modules=All&q=" + searchTerm, headerMap);
        return jsonObject.toJSONString();
    }

    public static void main(String[] args) throws Exception {
        System.out.println(SearchWeb(searchTerm));
    }

}
